package com.qf.smsplatform.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.smsplatform.constans.ResultCode;

/*
当前类的作用是用于返回统一的结果
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)//空的数据不会返回
/*2021/10/25*/public class R {
    private int code;//状态码，通过定义改码，我们可以告诉客户端当前请求的具体状态

    private String msg;//状态码的描述

    private Object data;//当前返回的数据

    public static R setOk(){
//        R r =new R();
//        r.setCode(ResultCode.SUCCESS);
//        r.setMsg("成功");
        return setOk(null);
    }
    public static R setOk(Object data){
        R r =new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }
    public static R setError() {
        return setError(null);
    }
    public static R setError(Object data){
//        R r =new R();
////        r.setCode(ResultCode.FAIL);
////        r.setMsg("失败");
////        r.setData(data);
        return setError(ResultCode.FAIL, "失败", data);
    }
    public static R setError(int code,String msg,Object data){
        R r =new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
